﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo5
{
    /// <summary>
    /// 使用二维数组管理成绩表
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            string[,] grades = {
                { "姓名","C#","数据库","英语","体育" },
                { "张无忌","90","95","98","90" },
                {  "张三丰","99","99","98","97"  },
                { "赵敏","80","85","78","80"  },
            };

            // 成绩表输出
            for(int i = 0; i < grades.GetLength(0); i++)
            {
                for (int j = 0; j < grades.GetLength(1); j++)
                    Console.Write($"{grades[i, j]}\t");

                Console.WriteLine();
            }

            //// 修改赵敏英语为95分
            //grades[3, 3] = "95";
            //Console.WriteLine("修改赵敏英语为95分");

            //for (int i = 1; i < grades.GetLength(0); i++)
            //    grades[i, 4] = "85";
            //Console.WriteLine("修改所有的体育为85分");

            //// 成绩表输出
            //for (int i = 0; i < grades.GetLength(0); i++)
            //{
            //    for (int j = 0; j < grades.GetLength(1); j++)
            //        Console.Write($"{grades[i, j]}\t");
            //    Console.WriteLine();
            //}

            // 统计出每位同学的总分
            string[] totals = new string[grades.GetLength(0)];
            string[] avgs = new string[grades.GetLength(0)];
            totals[0] = "总分";
            avgs[0] = "平均分";
            for (int i = 1; i < grades.GetLength(0); i++)
            {
                int total = 0;
                for (int j = 1; j < grades.GetLength(1); j++)
                    total += Convert.ToInt32(grades[i, j]);

                // 把总分存入数组
                totals[i] = total.ToString();
                avgs[i] =( total /(grades.GetLength(1)-1)).ToString();
            }
            // 输出总分平均分
            for (int i = 0; i < grades.GetLength(0); i++)
                Console.WriteLine($"{grades[i, 0]}\t{totals[i]}\t{avgs[i]}");

            // 交叉数组
            string[][] cities = new string[10][];
            cities[0]=new string[] { "广西","南宁","柳州" };
            cities[1] = new string[] { "广东", "广州", "湛江", "珠海" };

            Console.ReadKey();
        }
    }
}
